package commandPatern;

import java.sql.SQLException;
import java.util.List;
import java.util.ArrayList;
import java.util.Stack;
import java.util.Vector;

public class StoreCommands {
	private Stack<Command> undo = new Stack<Command>();
	private Stack<Command> rendo = new Stack<Command>();
	private static StoreCommands store = null;

	private StoreCommands() {
	}

	static public StoreCommands getInstance() {
		if (store == null) {
			store = new StoreCommands();
		}
		return store;
	}

	public void add(Command com) {
		System.out.println("add");
		undo.add(com);
		rendo.clear();
	}

	public void clearStacks() {
		rendo.clear();
		undo.clear();
	}

	public void undo() throws InstantiationException, IllegalAccessException,
			ClassNotFoundException, SQLException {
		Command cmd = undo.pop();
		rendo.push(cmd);
		cmd.undo();
	}

	public void rendo() throws InstantiationException, IllegalAccessException,
			ClassNotFoundException, SQLException {
		Command cmd = rendo.pop();
		undo.push(cmd);
		cmd.rendoo();
	}

	public boolean canUndo() {
		if (!undo.isEmpty())
			return true;

		return false;
	}

	public boolean canRendoo() {

		if (!rendo.isEmpty())
			return true;
		return false;
	}
}
